$(function () {
    let url = 'http://localhost:8080/api/v1';
    $.ajax({
        type: 'get',
        url: url + '/admin/user/detail',
        success: function (backData) {
            if (backData.code == 200) {
                for (let key in backData.data) {
                    $(`.${key}`).val(backData.data[key]);
                }
                $('.user_pic').attr('src', backData.data.userPic);
            }
        }
    });



    $('#exampleInputFile').on('change', function () {
        let file = this.files[0];
        let url = URL.createObjectURL(file);
        $('.user_pic').attr('src', url);
    });



    $('.btn-edit').on('click', function (event) {
        event.preventDefault();
        let fd = new FormData(document.querySelector('#form'));
        $.ajax({
            type: 'post',
            url: url + '/admin/user/edit',
            data: fd,
            contentType: false,
            processData: false,
            success: function (backData) {
                alert(backData.msg);
                if (backData.code == 200) {
                    parent.window.location.reload();
                }
            }
        })
    })
})